// 顶部广告关闭功能
document.addEventListener('DOMContentLoaded', function() {
    const topAd = document.querySelector('.top-ad');
    const closeAdBtn = document.querySelector('.close-ad');
    
    // 5秒后自动关闭广告
    setTimeout(() => {
        topAd.classList.add('collapsed');
    }, 5000);
    
    // 点击关闭按钮
    closeAdBtn.addEventListener('click', function() {
        topAd.classList.add('collapsed');
    });
    
    // 轮播图功能
    const carouselInner = document.querySelector('.carousel-inner');
    const carouselItems = document.querySelectorAll('.carousel-item');
    const prevBtn = document.querySelector('.prev');
    const nextBtn = document.querySelector('.next');
    const indicators = document.querySelectorAll('.carousel-indicators span');
    
    let currentIndex = 0;
    const itemWidth = carouselItems[0].clientWidth;
    const totalItems = carouselItems.length;
    
    function updateCarousel() {
        carouselInner.style.transform = `translateX(-${currentIndex * itemWidth}px)`;
        
        // 更新指示器状态
        indicators.forEach((indicator, index) => {
            indicator.classList.toggle('active', index === currentIndex);
        });
    }
    
    // 下一张
    nextBtn.addEventListener('click', function() {
        currentIndex = (currentIndex + 1) % totalItems;
        updateCarousel();
    });
    
    // 上一张
    prevBtn.addEventListener('click', function() {
        currentIndex = (currentIndex - 1 + totalItems) % totalItems;
        updateCarousel();
    });
    
    // 指示器点击
    indicators.forEach((indicator, index) => {
        indicator.addEventListener('click', function() {
            currentIndex = index;
            updateCarousel();
        });
    });
    
    // 自动轮播
    setInterval(() => {
        currentIndex = (currentIndex + 1) % totalItems;
        updateCarousel();
    }, 5000);
});